var t = getApp();

Component({
    properties: {
        showVer: {
            type: null
        }
    },
    data: {
        showVerification: !1,
        imgcode: "",
        count: "",
        form: {
            mobile: "",
            code: "",
            captcha: ""
        },
        showContent: !1,
        protocol_title: "",
        protocol_content: ""
    },
    observers: {
        showVer: function(t) {
            this.setData({
                showVerification: t
            }), console.log(t, ";sdasdasd");
        }
    },
    lifetimes: {
        attached: function() {
            this.initShow();
        },
        detached: function() {}
    },
    methods: {
        showContentTap: function() {
            this.setData({
                showContent: !0
            });
        },
        initShow: function() {
            this.getimgdata(), this.getProtocolInfo(), this.showVerification = !0;
        },
        closeShow: function() {
            this.setData({
                showVerification: !1
            });
        },
        hide: function() {
            this.setData({
                showVerification: !1
            });
        },
        getProtocolInfo: function() {
            var e = this, o = t.getNetAddresss("setting.get-member-protocol");
            t._getNetWork({
                showToastIn: !1,
                url: o,
                success: function(t) {
                    var o = t.data;
                    1 == o.result && e.setData({
                        protocol_content: o.data.content,
                        protocol_title: o.data.title
                    });
                },
                fail: function(t) {}
            });
        },
        getimgdata: function() {
            var e = this, o = t.getNetAddresss("home-page.getCaptcha");
            t._getNetWork({
                showToastIn: !1,
                url: o,
                success: function(t) {
                    var o = t.data;
                    1 == o.result && (o.data.captcha.status && "0" == o.data.captcha.status && e.setData({
                        imgcode: null
                    }), o.data.captcha.img && e.setData({
                        imgcode: o.data.captcha.img
                    }));
                },
                fail: function(t) {}
            });
        },
        tapPhone: function(t) {
            console.log(t);
            var e = t.currentTarget.dataset.key, o = t.detail.value;
            "phone" == e ? this.setData({
                "form.mobile": o
            }) : "cap" == e ? this.setData({
                "form.captcha": o
            }) : "code" == e && this.setData({
                "form.code": o
            });
        },
        VerificationCode: function() {
            if (t._isTextEmpty(this.data.form.captcha) && this.data.imgcode) wx.showToast({
                title: "请填图形验证码",
                icon: "none",
                duration: 1e3
            }); else if (t._isTextEmpty(this.data.form.mobile)) wx.showToast({
                title: "请填写手机号",
                icon: "none",
                duration: 1e3
            }); else {
                wx.showLoading({
                    title: "发送中"
                });
                var e = this,o = t.getNetAddresss("SMS.index");
                //  o = t.getNetAddresss("member.register.sendCodeV2");
                t._getNetWork({
                    showToastIn: !1,
                    url: o,
                    data: {
                        mobile: this.data.form.mobile,
                        captcha: this.data.form.captcha
                    },
                    success: function(t) {
                        var o = t.data;
                        wx.hideLoading({
                            success: function(t) {}
                        }), 1 == o.result ? e.getCode() : (e.setData({
                            "form.captcha": ""
                        }), e.getimgdata());
                    },
                    fail: function(t) {}
                });
            }
        },
        getCode: function() {
            var t = this;
            this.data.timer || (this.data.count = 60, this.data.timer = setInterval(function() {
                t.data.count > 0 && t.data.count <= 60 ? (t.data.count--, t.setData({
                    count: t.data.count
                })) : (clearInterval(t.timer), t.data.count = 0, t.data.timer = null, t.setData({
                    count: t.data.count,
                    timer: t.data.timer
                }));
            }, 1e3));
        },
        bindMobile: function() {
            if (t._isTextEmpty(this.data.form.mobile)) wx.showToast({
                title: "手机号码不能为空",
                icon: "none",
                duration: 1e3
            }); else if (t._isMoblie(this.data.form.mobile)) wx.showToast({
                title: "请输入正确的手机号",
                icon: "none",
                duration: 1e3
            }); else if (t._isTextEmpty(this.data.form.code)) wx.showToast({
                title: "请填写验证码",
                icon: "none",
                duration: 1e3
            }); else if (this.imgcode && t._isTextEmpty(this.data.form.captcha)) wx.showToast({
                title: "图形验证码不能为空",
                icon: "none",
                duration: 1e3
            }); else {
                var e = this, o = t.getNetAddresss("member.member.justBindMobile");
                t._getNetWork({
                    showToastIn: !1,
                    url: o,
                    data: this.data.form,
                    success: function(t) {
                        1 == t.data.result && (wx.showToast({
                            title: "绑定成功！",
                            icon: "none",
                            duration: 1e3
                        }), e.setData({
                            showContent: !1,
                            showVerification: !1
                        }), e.triggerEvent("bindSuccess"));
                    },
                    fail: function(t) {}
                });
            }
        }
    }
});